import request from "@/utils/request.js";

export const listUser = async () => {
    const res = await request.get('/user/list');
    return res.map(e => ({...e, value: e.id, label: e.nickname}))
}

export const typeOptions = [
    {value: 1, label: '代购', type: 'primary'},
    {value: 2, label: '代取快递', type: 'info'},
    {value: 3, label: '代办事务', type: 'warning'},
]
export const statusOptions = [
    {value: 1, label: '待接单', type: 'primary'},
    {value: 2, label: '进行中', type: 'info'},
    {value: 3, label: '已完成', type: 'warning'},
    {value: 4, label: '已取消', type: 'success'},
    {value: 5, label: '已关闭', type: 'primary'},
]
export const isAbnormalOptions = [
    {value: 0, label: '正常', type: 'primary'},
    {value: 1, label: '异常', type: 'info'},
]

export const fields = [
    {
        prop: 'publisherId',
        label: '所属发布者',
        type: 'remote-select',
        api: listUser,
        width: 100,
    },
    {
        prop: 'acceptorId',
        label: '所属接单者',
        type: 'remote-select',
        api: listUser,
        width: 100,
    },
    {
        prop: 'name',
        label: '任务标题',
        type: 'text',
        search: true,
        width: 170,
    },
    {
        prop: 'description',
        label: '任务描述',
        type: 'longtext',
        width: '150',
    },
    {
        prop: 'reward',
        label: '报酬金额',
        type: 'number',
        width: 120,
    },
    {
        prop: 'campus',
        label: '校区',
        type: 'text',
        width: 170,
    },
    {
        prop: 'originAddress',
        label: '任务起点',
        type: 'text',
        search: true,
        width: 220,
    },
    {
        prop: 'destAddress',
        label: '任务目的地',
        type: 'text',
        search: true,
        width: 220,
    },
    {
        prop: 'originLocation',
        label: '起点经纬度',
        type: 'text',
        width: 170,
        hidden: true,
    },
    {
        prop: 'destLocation',
        label: '目的地经纬度',
        type: 'text',
        width: 170,
        hidden: true,
    },
    {
        prop: 'distance',
        label: '距离',
        type: 'number',
        width: 120,
    },
    {
        prop: 'type',
        label: '任务类型',
        type: 'tag',
        options: typeOptions,
        search: true,
        width: 120,
    },
    {
        prop: 'status',
        label: '任务状态',
        type: 'tag',
        options: statusOptions,
        search: true,
        width: 120,
    },
    {
        prop: 'deadline',
        label: '截止时间',
        type: 'datetime',
        width: 190,
    },
    {
        prop: 'estimatedTime',
        label: '预计分钟数',
        type: 'number',
        width: 120,
    },
    {
        prop: 'progress',
        label: '进度百分比',
        type: 'number',
        width: 120,
    },
    {
        prop: 'isAbnormal',
        label: '是否异常',
        type: 'switch',
        options: isAbnormalOptions,
        search: true,
        width: 170,
    },
    {
        prop: 'abnormalReason',
        label: '异常原因',
        type: 'text',
        width: 170,
    },
    {
        prop: 'acceptTime',
        label: '接单时间',
        type: 'datetime',
        width: 190,
    },
    {
        prop: 'createTime',
        label: '创建时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    },
    {
        prop: 'updateTime',
        label: '更新时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    }
]